| API Documentation |  |

- MAIN PAGE
- NAMESPACES
- CLASSES

Public Member Functions | List of all members
nkResources::ResourceManager Class Referencefinal

Manager helping with path finding and resource loading. More...

Inheritance diagram for nkResources::ResourceManager:

## Public Member Functions
void | setWorkingPath (nkMemory::StringView path)
void | setWorkingPathAbsolute (nkMemory::StringView path)
nkMemory::StringView | getWorkingPath () const
nkMemory::StringView | getWorkingPathAbsolute () const
nkMemory::StringView | getLaunchedPath () const
void | setLaunchedPath (nkMemory::StringView path)
nkMemory::String | getRelativeFromAbsolute (nkMemory::StringView absolutePath) const
nkMemory::String | getAbsoluteFromRelative (nkMemory::StringView relativePath) const
nkMemory::String | getRelativeFromWorkingDir (nkMemory::StringView workingPath) const
nkMemory::String | getAbsoluteFromWorkingDir (nkMemory::StringView workingPath) const
nkMemory::String | getFromWorkingDirFromRelative (nkMemory::StringView relativePath) const
nkMemory::String | getFromWorkingDirFromAbsolute (nkMemory::StringView absolutePath) const
bool | checkFileExists (nkMemory::StringView filePathAbs) const
void | checkFolderExists (nkMemory::StringView path)
nkMemory::Buffer | loadFileIntoMemory (nkMemory::StringView filePathAbs, bool silent=false)
bool | saveFileToDisk (nkMemory::StringView outPathAbs, nkMemory::BufferView<> data, bool silent=false)

## Detailed Description

Manager helping with path finding and resource loading.

An important role if this component is to allow to setup data path in one location, for the whole engine. In other words, the components working with resource path will use this manager to reconstruct all the paths they would need. For this, they will need paths relative to the working directory, unless specified otherwise.
Typical usage would be :

// Set the working path, or leave it as the default which is the launch path
nkResources::ResourceManager::getInstance()->setWorkingPathAbsolute("C:/MyData/") ;
// Work with other components, setting up a resource at some point
...
texture->setPath("Textures/noise.jpg") ;
...
// The resource path will be looked up relative to the working directory automatically during loading (C:/MyData/Textures/noise.jpg)
texture->load() ;

Globally, it uses 3 keywords for all paths it manipulates :

- launched path : defaults to the path from where the program is launched.
- working path : path an application can set as a reference, defaulting to the launched path.

Transformations from one path to another use these keywords :

- relative : relative to the launched path.
- from working path : relative to the working path.

## Member Function Documentation

## ◆ setWorkingPath()

void nkResources::ResourceManager::setWorkingPath | ( | nkMemory::StringView | path | ) |

Sets the working path.

Parameters

  path | The path of the wanted path, relative to the path from where the software is launched.

## ◆ setWorkingPathAbsolute()

void nkResources::ResourceManager::setWorkingPathAbsolute | ( | nkMemory::StringView | path | ) |

Sets the working path.

Parameters

  path | The path of the wanted path, absolute.

## ◆ getWorkingPath()

nkMemory::StringView nkResources::ResourceManager::getWorkingPath | ( |  | ) | const

Returns
  The current set working path, as a path relative to the path from where the software is launched.

## ◆ getWorkingPathAbsolute()

nkMemory::StringView nkResources::ResourceManager::getWorkingPathAbsolute | ( |  | ) | const

Returns
  The current set working path, absolute.

## ◆ getLaunchedPath()

nkMemory::StringView nkResources::ResourceManager::getLaunchedPath | ( |  | ) | const

Returns
  The path from where the program was launched.

## ◆ setLaunchedPath()

void nkResources::ResourceManager::setLaunchedPath | ( | nkMemory::StringView | path | ) |

Allows to override the path from which the program is launched.

Remarks
  This path is already populated by default by the ResourceManager. Call this function only if you really need to.

## ◆ getRelativeFromAbsolute()

nkMemory::String nkResources::ResourceManager::getRelativeFromAbsolute | ( | nkMemory::StringView | absolutePath | ) | const

Converts a path, from absolute, to a path relative to the launched path.

Parameters

  absolutePath | The absolute path to convert.

Returns
  The path converted.

## ◆ getAbsoluteFromRelative()

nkMemory::String nkResources::ResourceManager::getAbsoluteFromRelative | ( | nkMemory::StringView | relativePath | ) | const

Converts a path, from relative to the launched directory, to absolute.

Parameters

  relativePath | The relative path to convert.

Returns
  The path converted.

## ◆ getRelativeFromWorkingDir()

nkMemory::String nkResources::ResourceManager::getRelativeFromWorkingDir | ( | nkMemory::StringView | workingPath | ) | const

Converts a path, from relative to the working directory, to relative to the launched path.

Parameters

  workingPath | The path relative to the working directoy to convert.

Returns
  The path converted.

## ◆ getAbsoluteFromWorkingDir()

nkMemory::String nkResources::ResourceManager::getAbsoluteFromWorkingDir | ( | nkMemory::StringView | workingPath | ) | const

Converts a path, from relative to the working directory, to absolute.

Parameters

  workingPath | The path relative to the working directoy to convert.

Returns
  The path converted.

## ◆ getFromWorkingDirFromRelative()

nkMemory::String nkResources::ResourceManager::getFromWorkingDirFromRelative | ( | nkMemory::StringView | relativePath | ) | const

Converts a path, from relative to the launched directory, to relative to the working directory.

Parameters

  relativePath | The path relative to the launched path to convert.

Returns
  The path converted.

## ◆ getFromWorkingDirFromAbsolute()

nkMemory::String nkResources::ResourceManager::getFromWorkingDirFromAbsolute | ( | nkMemory::StringView | absolutePath | ) | const

Converts a path, from absolute, to relative to the working directory.

Parameters

  absolutePath | The absolute path to convert.

Returns
  The path converted.

## ◆ checkFileExists()

bool nkResources::ResourceManager::checkFileExists | ( | nkMemory::StringView | filePathAbs | ) | const

Checks if a file exists for a certain path.

Parameters

  filePathAbs | The absolute path to check.

Returns
  True if the file exists, false otherwise.

## ◆ checkFolderExists()

void nkResources::ResourceManager::checkFolderExists | ( | nkMemory::StringView | path | ) |

Checks if a folder exists for a certain path.

Parameters

  path | The absolute path to check.

Returns
  True if the file exists, false otherwise.

## ◆ loadFileIntoMemory()

nkMemory::Buffer nkResources::ResourceManager::loadFileIntoMemory | ( | nkMemory::StringView | filePathAbs,
|  | bool | silent = `false`
| ) |  |

Loads a file into memory.

Parameters

  filePathAbs | The path to the file, absolute.
  silent | If a failure in finding the requested file should not be logged. True for no logging, false otherwise.

Returns
  A binary buffer holding the file data.

## ◆ saveFileToDisk()

bool nkResources::ResourceManager::saveFileToDisk | ( | nkMemory::StringView | outPathAbs,
|  | nkMemory::BufferView<> | data,
|  | bool | silent = `false`
| ) |  |

Saves a file to the disk, writing the binary buffer provided as a parameter.

Parameters

  outPathAbs | The absolute path to save the file to.
  data | The binary data to save.
  silent | If a failure in finding the requested file should not be logged. True for no logging, false otherwise.

Returns
  Whether the operation was successful (true) or not (false).

The documentation for this class was generated from the following file:

- Documentation/Headers/NilkinsResources/ResourceManager.h